<?php
App::uses('AppModel', 'Model');
/**
*@description: Staff model using for login, logout ...
*@author: phuongnv
*@since: Dec 20, 2013
*/
class Staff extends AppModel {

    /**
    * Use database config
    *
    * @var string
    */
    //public $useDbConfig = 'admin';

	/**
 	* Display field
 	*
 	* @var string
 	*/
    public $displayField = 'name';

    /**
    * Validation rules
    *
    * @var array
    */
    public $validate = array(
        'loginid' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'password' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'name' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'group_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'office_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'del_flg' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed

	/**
 	* belongsTo associations
 	*
 	* @var array
 	*/
    /*
    public $belongsTo = array(
        'Group' => array(
            'className' => 'Group',
            'foreignKey' => 'group_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Office' => array(
            'className' => 'Office',
            'foreignKey' => 'office_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
    */
    /**
     * 
      * Get staff loginid by offcice id
      *
      * @author Nguyen Van Phuong <phuongnv6231@setacinq.com.vn>
      * @since 1.0.0
      * @param: 
      * @return int
     */
    function getStaffByOfficeId($officeId) {
        return $this->find('all', array(
            'fields' => array('loginid'),
            'conditions' => array(
                'Staff.office_id' => $officeId,
                'Staff.del_flg' => 0
            )
        ));
    }
}
